<template>
  <el-dialog
    v-model="dialogShow"
    :close-on-click-modal="false"
    :destroy-on-close="false"
    custom-class="mydialog"
    width="500px"
    title="申请配送商完成处理"
    @close="close"
  >
    <el-form
      ref="formRef"
      :model="formData"
      :label-width="formLabelWidth"
      size="small"
      :rules="formRules"
    >
      <el-form-item
        label="处理结果："
        prop="disApplyStatus"
      >
        <el-radio-group v-model="formData.disApplyStatus">
          <el-radio label="-1">未达成签约</el-radio>
          <el-radio label="1">已签约</el-radio>
        </el-radio-group>
      </el-form-item>
    </el-form>
    <template #footer>
      <div
        class="dialog-footer"
        style="display:flex;justify-content:center;align-items:center;"
      >
        <el-button
          class="border-btn"
          size="small"
          @click="close"
        >取消</el-button>
        <el-button
          class="main-btn"
          size="small"
          type="primary"
          @click="confirm"
        >确定</el-button>
      </div>
    </template>
  </el-dialog>
</template>

<script>
import {defineComponent, getCurrentInstance, inject, reactive, ref, toRefs,} from 'vue'

export default defineComponent({
  name: 'DealApply',
  emits: ['refresh'],
  setup(props, context) {
    const api = inject('api')
    const formRef = ref(null)
    const currentInstance = getCurrentInstance()
    var datas = reactive({
      formData: {
        id: 0,
        disApplyStatus: '',
      },
    })
    var formRules = reactive({
      disApplyStatus: [
        { required: true, message: '请选择处理结果', trigger: 'change' },
      ],
    })
    var formLabelWidth = ref(100)
    var dialogShow = ref(false)
    const open = (row) => {
      datas.formData.id = row.id
      dialogShow.value = true
    }
    const close = () => {
      dialogShow.value = false
      formRef.value.resetFields()
    }
    const confirm = () => {
      formRef.value.validate((valid) => {
        if (valid) {
          api.distributors
            .DISTRIBUTORS_APPLAY_COMPLETE(datas.formData)
            .then((res) => {
              if (res.code === 0) {
                currentInstance.proxy.customMessage({
                  type: 'success',
                  message: '处理完成',
                })
                context.emit('refresh')
                close()
              }
            })
        } else {
          console.log('error submit!!')
          return false
        }
      })
    }
    return {
      ...toRefs(datas),
      formRef,
      formRules,
      formLabelWidth,
      dialogShow,
      open,
      close,
      confirm,
    }
  },
})
</script>
